﻿using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class AdminDAL:PageDAL<UsersModel>
    {
        public UsersModel GetModelByID(string TableName, int id)
        {
            string sql = $"select * from  {TableName} where id='{id}'";
            DataTable dt = new DBHelper().GetDataTable(sql);
            UsersModel model = new UsersModel()
            {
                ID = int.Parse(dt.Rows[0]["id"].ToString()),
                Name = dt.Rows[0]["Name"].ToString(),
                Pwd = dt.Rows[0]["Pwd"].ToString(),
                roleID = int.Parse(dt.Rows[0]["roleID"].ToString()),
            };
            return model;
        }

        public DataTable LJA(string v1, string v2)
        {
            string sql = $"Select a.* , b.roleName from {v1} a,{v2} b where b.id = a.{v2}id";
            return new DBHelper().GetDataTable(sql);
        }

        public DataTable SelectLJA(string tableOne, string tableTwo, string mz)
        {
            string sql = $"select * from {tableOne} a,{tableTwo} b where Name like '%{mz}%' and b.ID=a.{tableTwo}ID";
            return new DBHelper().GetDataTable(sql);
        }
    }
}
